package com.bnzj.core.persistence.repository;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.NoRepositoryBean;

@NoRepositoryBean
public interface BaseRepository<T, ID extends Serializable> extends JpaRepository<T, ID>,JpaSpecificationExecutor<T> {
    @Query("select id from #{#entityName}")
	Set<ID> findAllId();
    
    /**
     * 逻辑删除
     * @param id
     */
    @Modifying
    @Query("update #{#entityName} set deleted = 1, modifyBy = ?2, modifyName = ?3, modifyTime = ?4 where id = ?1")
    void logicDelete(ID id, String modifyBy, String modifyName, Date modifyTime);
    
    /**
     * 禁用
     * @param id
     */
    @Modifying
    @Query("update #{#entityName} set enabled = 0, modifyBy = ?2, modifyName = ?3, modifyTime = ?4 where id = ?1")
    void disable(ID id, String modifyBy, String modifyName, Date modifyTime);
}
